"""
旅游平台 Pydantic 模式定义
"""
from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class AttractionBase(BaseModel):
    """景点基础模式"""
    name: str = Field(..., description="景点名称")
    description: Optional[str] = None
    type: str = "scenic"
    province: Optional[str] = None
    city: Optional[str] = None
    district: Optional[str] = None
    address: Optional[str] = None
    longitude: Optional[float] = None
    latitude: Optional[float] = None
    price: float = 0.0
    original_price: Optional[float] = None
    cover_image: Optional[str] = None
    images: Optional[str] = None
    tags: Optional[str] = None
    is_recommended: bool = False


class AttractionCreate(AttractionBase):
    """创建景点"""
    pass


class AttractionInfo(AttractionBase):
    """景点信息"""
    id: int
    rating: float = 0.0
    review_count: int = 0
    is_active: bool = True
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True


class BannerInfo(BaseModel):
    """轮播图信息"""
    id: int
    title: Optional[str] = None
    image_url: str
    link_url: Optional[str] = None
    link_type: Optional[str] = None
    link_id: Optional[int] = None
    sort: int = 0
    
    class Config:
        from_attributes = True


class CategoryInfo(BaseModel):
    """分类信息"""
    id: int
    name: str
    icon: Optional[str] = None
    image_url: Optional[str] = None
    sort: int = 0
    
    class Config:
        from_attributes = True


class HomePageResponse(BaseModel):
    """首页响应"""
    banners: List[BannerInfo] = []
    categories: List[CategoryInfo] = []
    recommended_attractions: List[AttractionInfo] = []
    popular_attractions: List[AttractionInfo] = []
    merchant_attractions: List[AttractionInfo] = []  # 商家发布的信息


class AttractionListResponse(BaseModel):
    """景点列表响应"""
    total: int
    page: int
    page_size: int
    attractions: List[AttractionInfo] = []


class RecommendationResponse(BaseModel):
    """推荐响应"""
    user_id: int
    algorithm: str = Field(..., description="推荐算法：user-based, item-based, hybrid")
    attractions: List[AttractionInfo] = []
    scores: Optional[dict] = Field(None, description="推荐分数（物品ID -> 分数）")
    message: Optional[str] = None



